list-[id].vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 二级标题-->
  10. <HomeListSecondaryHeading v-if="parent_name != ''" :name="parent_name" :nav="secondNav" :pinyin="parent_pinyin"></HomeListSecondaryHeading>
  11. <!-- 资讯列表 -->
  12. <div class="newsList">
  13. <div class="inner">
  14. <div class="innerLeft">
  15. <!-- 面包屑导航 -->
  16. <div class="breadcrumb phone_none">
  17. <div class="inner">
  18. <span class="location">当前位置:</span>
  19. <el-breadcrumb :separator-icon="ArrowRight">
  20. <el-breadcrumb-item>
  21. <NuxtLink to="/">首页</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item v-if="parent_name !=''">
  24. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  25. </el-breadcrumb-item>
  26. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  27. </el-breadcrumb>
  28. </div>
  29. </div>
  30. <div class="breadcrumb_box pc_none">
  31. <span class=" ">当前位置:</span>
  32. <NuxtLink to="/">首页</NuxtLink>
  33. <span class=" " v-if="parent_name !=''">&gt;</span>
  34. <NuxtLink v-if="parent_name !=''" :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  35. <span class="" >&gt;</span>
  36. {{ name }}
  37. </div>
  38. <ul class="list">
  39. <li v-for="(item, index) in newsList" :key="index">
  40. <NuxtLink :href="path + item.id + '.html' " :title="item.alias">
  41. <span class="listTitle">{{ item.title }}</span>
  42. <span class="time">{{ getTime(item.updated_at, 'month', 1) }}</span>
  43. </NuxtLink>
  44. </li>
  45. </ul>
  46. <!-- 分页器 -->
  47. <div class="pagination page_phone_none" v-if="total > 0">
  48. <el-pagination
  49. size="small"
  50. background
  51. layout="prev, pager, next"
  52. :total="total"
  53. class="mt-4"
  54. :page-size="pageSize"
  55. :current-page="pageNum"
  56. prev-text="上一页"
  57. next-text="下一页"
  58. @current-change="changePage"
  59. />
  60. </div>
  61. <div class="pagination page_pc_none" v-if="total > 0">
  62. <el-pagination pager-count="5" size="small" background layout=" pager " :total="total"
  63. class="mt-4" v-model:page-size="pageSize" :current-page="pageNum"
  64. @current-change="changePage" />
  65. </div>
  66. </div>
  67. <div class="innerRight">
  68. <DetailHotNews></DetailHotNews>
  69. <DetailHotNews2></DetailHotNews2>
  70. </div>
  71. </div>
  72. </div>
  73. <!-- 列表页广告二 -->
  74. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  75. <!-- 页面底部 -->
  76. <HomeFoot1></HomeFoot1>
  77. </div>
  78. </template>
  79. <script setup>
  80. //1.页面必备依赖 start ---------------------------------------->
  81. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  82. import { ArrowRight } from '@element-plus/icons-vue'
  83. import { ref, onMounted } from 'vue';
  84. //1.页面必备依赖 end ---------------------------------------->
  85. //2.路径 start---------------------------------------->
  86. //当前列表名称
  87. const route = useRoute();
  88. let articleId = 0;//列表需要使用的导航id
  89. const targetSegment1 = getRoutePath(1);//根据路由反向查询导航id
  90. const targetSegment2 = getRoutePath(2);//根据路由反向查询导航id
  91. let pageNum = ref(1);//获得路由里面的分页数据
  92. let path ='/' + targetSegment1 + '/' + targetSegment2 + '/';
  93. //通过导航路径反向查询导航id
  94. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  95. method: 'GET',
  96. query: {
  97. 'pinyin': targetSegment1 + '/' + targetSegment2,
  98. },
  99. });
  100. if(getRouteId.code == 200){
  101. articleId = getRouteId.data.category_id
  102. }else{
  103. console.log("后端错误反馈:",getRouteId.message)
  104. }
  105. pageNum.value = parseInt(route.params.id);
  106. //2.路径 end---------------------------------------->
  107. //3.列表 start ---------------------------------------->
  108. let total = ref(1);
  109. let pageSize = ref(20);
  110. const newsList = ref([]);
  111. let newslists = async () => {
  112. const listData = await requestDataPromise('/web/getWebsiteCompanyList', {
  113. method: 'GET',
  114. query: {
  115. 'page': pageNum.value,
  116. 'pageSize': pageSize.value,
  117. 'category_id': articleId
  118. },
  119. });
  120. if (listData.code == 200) {
  121. newsList.value = listData.data.data;
  122. console.log('newslist111111111111',newsList.value);
  123. total.value = listData.data.count;
  124. } else {
  125. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  126. console.log("错误位置:获取新闻列表")
  127. console.log("后端错误反馈:", listData.message)
  128. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  129. }
  130. }
  131. newslists();
  132. //分页
  133. let changePage = (value) => {
  134. console.log("当前页码", value);
  135. navigateTo(`/${targetSegment2}/${value}.html`)
  136. }
  137. //3.列表 end ---------------------------------------->
  138. //4.面包屑 start---------------------------------------->
  139. //3.1 获得页面名称
  140. const name = ref('')
  141. let getPageName = async () => {
  142. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  143. method: 'GET',
  144. query: {
  145. 'catid': articleId
  146. },
  147. });
  148. if (pageName.code == 200) {
  149. name.value = pageName.data.alias
  150. } else {
  151. console.log("错误位置:设置页面标题")
  152. }
  153. }
  154. getPageName();
  155. //3.2 获得父级栏目
  156. const parent_name = ref([]);
  157. const parent_id = ref([]);
  158. const parent_pinyin = ref("");
  159. let getParentNav = async () => {
  160. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  161. method: 'GET',
  162. query: {
  163. 'catid': articleId
  164. },
  165. });
  166. if (listData.code == 200) {
  167. console.log(111999)
  168. console.log(listData.data);
  169. parent_name.value = listData.data.parent_name;
  170. parent_id.value = listData.data.parent_id;
  171. parent_pinyin.value = listData.data.parent_pinyin;
  172. } else {
  173. console.log("错误位置:获取父级栏目")
  174. }
  175. getSecondNav();
  176. }
  177. getParentNav();
  178. // 3.3获取二级栏目
  179. const secondNav = ref([]);
  180. let getSecondNav = async () => {
  181. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  182. method: 'GET',
  183. query: {
  184. 'placeid': 1,
  185. 'pid': parent_id.value,
  186. 'num': 20,
  187. },
  188. });
  189. console.log('listData', listData);
  190. if (listData.code == 200) {
  191. secondNav.value = listData.data;
  192. } else {
  193. console.log("错误位置:获取二级栏目列表")
  194. }
  195. }
  196. //4.面包屑 end ---------------------------------------->
  197. //5.设置seo信息 start---------------------------------------->
  198. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  199. method: 'GET',
  200. query: {
  201. 'catid': articleId
  202. },
  203. });
  204. if (setData.code == 200) {
  205. let seoTitle = setData.data.seo_title;
  206. let seoDescription = setData.data.seo_description;
  207. let seoKeywords = setData.data.seo_keywords;
  208. let seoSuffix = setData.data.suffix;
  209. let seoName = setData.data.website_name;
  210. useSeoMeta({
  211. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  212. meta: [
  213. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  214. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  215. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  216. ]
  217. });
  218. } else {
  219. console.log("错误位置:设置列表页面SEO数据")
  220. }
  221. //5.设置seo信息 end---------------------------------------->
  222. //6.广告 start---------------------------------------->
  223. let adImg1 = ref({});
  224. let adImg2 = ref({});
  225. onMounted(async () => {
  226. //从客户端获取行政职能部门 加快打开速度
  227. const { $webUrl, $CwebUrl } = useNuxtApp();
  228. //广告1
  229. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0001`
  230. const responseAd1 = await fetch(url, {
  231. headers: {
  232. 'Content-Type': 'application/json',
  233. 'Userurl': $CwebUrl,
  234. 'Origin': $CwebUrl
  235. }
  236. });
  237. const resultAd1 = await responseAd1.json();
  238. adImg1.value = resultAd1.data[0];
  239. //广告2
  240. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0002`
  241. const responseAd2 = await fetch(url2, {
  242. headers: {
  243. 'Content-Type': 'application/json',
  244. 'Userurl': $CwebUrl,
  245. 'Origin': $CwebUrl
  246. }
  247. });
  248. const resultAd2 = await responseAd2.json();
  249. adImg2.value = resultAd2.data[0];
  250. })
  251. //6.广告 end---------------------------------------->
  252. </script>
  253. <style lang="less" scoped>
  254. @import url('@/assets/css/list.less');
  255. </style>
  256. <style lang="less" scoped>
  257. @media screen and (min-width:801px) {
  258. /*pc*/
  259. .page_pc_none {
  260. display: none !important;
  261. }
  262. .pc_none {
  263. display: none;
  264. }
  265. }
  266. @media screen and (max-width:800px) {
  267. /*ipad_phone*/
  268. .newsList .inner {
  269. width: 92%;
  270. margin: 0px auto 0px;
  271. }
  272. .newsList .inner .innerLeft {
  273. width: 100%;
  274. float: none;
  275. }
  276. .newsList .inner .innerLeft {
  277. width: 100%;
  278. float: none;
  279. margin: 0px auto;
  280. }
  281. .newsList .inner .innerLeft .list li .time {
  282. display: none !important;
  283. }
  284. .newsList .inner .innerLeft .list li {
  285. display: block;
  286. width: 100%;
  287. padding: 14px 0 !important;
  288. }
  289. .newsList .inner .innerLeft .list li .listTitle {
  290. font-size: 16px;
  291. font-weight: normal !important;
  292. }
  293. .newsList .inner .innerLeft>.pagination {
  294. width: 100%;
  295. }
  296. .newsList .inner .innerLeft>.pagination .el-pagination.is-background .el-pager li {
  297. margin: 0px 4px;
  298. }
  299. .newsList .inner .innerLeft .list {
  300. margin-bottom: 10px;
  301. border-top: solid 1px #489d97;
  302. min-height:493px;
  303. }
  304. .breadcrumb_box {
  305. height: 22px;
  306. width: 100%;
  307. margin: 10px auto;
  308. word-break: keep-all;
  309. white-space: nowrap;
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. font-size: 14px;
  313. color: #666;
  314. * {
  315. font-size: 14px;
  316. display: inline;
  317. color: #666;
  318. line-height: 22px;
  319. height: 22px;
  320. margin-right: 5px;
  321. }
  322. }
  323. .newsList .inner .innerLeft>.pagination /deep/.el-pagination.is-background .el-pager li {
  324. margin: 0px 4px;
  325. }
  326. .newsList {
  327. margin-bottom: 23px;
  328. }
  329. .page_phone_none {
  330. display: none !important;
  331. }
  332. .innerRight {
  333. display: none;
  334. }
  335. .phone_none {
  336. display: none;
  337. }
  338. }
  339. </style>